home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / utmisc1 / alcun101.lha / romdump / ROMDump.s < prev   
Text File  |  1995-01-11  |  7KB  |  465 lines

  1. ;
  2. ; $Id: ROMDump.s,v 1.4 1995/01/11 18:21:36 ecd Exp ecd $
  3. ;
  4. ;  This file is part of ROMDump, a ROM dump utility for the HP48 Calculator.
  5. ;  Copyright (C) 1994  Eddie C. Dost  (ecd@dressler.de)
  6. ;
  7. ;  This program is free software; you can redistribute it and/or modify
  8. ;  it under the terms of the GNU General Public License as published by
  9. ;  the Free Software Foundation; either version 2 of the License, or
  10. ;  (at your option) any later version.
  11. ;
  12. ;  This program is distributed in the hope that it will be useful,
  13. ;  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. ;  GNU General Public License for more details.
  16. ;
  17. ;  You should have received a copy of the GNU General Public License
  18. ;  along with this program; if not, write to the Free Software
  19. ;  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. ;
  21. ; Usage:
  22. ;
  23. ; (2: hxs, 1: hxs --> ) pop start address from level 2,
  24. ;                       pop end address from level 1, and dump
  25. ;                       ROM to the serial at 9600 baud using
  26. ;                       lines of form "aaaaa:hhhhhhhhhhhhhhhh\n\r"
  27. ;                       with 16 nibbles ROM data hhhhhhhhhhhhhhhh
  28. ;                       at address aaaaa.
  29. ;
  30. ; machine independent addresses (supported by HP)
  31. ;
  32. AllowIntr    equ    $010e5
  33. DisableIntr    equ    $01115
  34. DOBINT        equ    $02911
  35. DOCOL        equ    $02d9d
  36. DOCODE        equ    $02dcc
  37. SEMI        equ    $0312b
  38. GETPTRLOOP    equ    $05143
  39. SAVPTR        equ    $0679b
  40. GETPTR        equ    $067d2
  41. CK2NOLASTWD    equ    $18a8d
  42. CKandDISPATCH1    equ    $18fb2
  43. VERSTRING    equ    $30794
  44. PopASavptr    equ    $3251c
  45. ;
  46. ; machine independent addresses (NOT supported by HP)
  47. ;
  48. POPHXS        equ    $53f8d
  49.  
  50. ;
  51. ; machine dependent addresses
  52. ;
  53. sx_GosubHidC    equ    $026bf
  54. sx_prog_low    equ    $700f1    ; IRAMBUFF
  55. sx_prog_high    equ    $f00f1    ; IRAMBUFF when RAM configured high
  56.  
  57. gx_GosubHidC    equ    $026ca
  58. gx_prog_low    equ    $800f5    ; IRAMBUFF
  59. gx_prog_high    equ    $c00f5    ; IRAMBUFF when RAM configured high
  60. gx_LINECOUNT    equ    $8069a
  61.  
  62. ;
  63. ; flags used
  64. ;
  65. sGX        equ    0
  66. sHIGH        equ    1
  67.  
  68. ;
  69. ; begin off assembler code
  70. ;
  71.     textr    "HPHP48-R"
  72.  
  73.     dcr.5    DOCOL
  74.     dcr.5    CK2NOLASTWD
  75.     dcr.5    CKandDISPATCH1
  76.     dcr.5    DOBINT
  77.     dcr.5    $000bb
  78.  
  79.     ;
  80.     ; only executed when (2: hxs, 1: hxs)
  81.     ;
  82.     dcr.5    DOCOL
  83.     dcr.5    VERSTRING
  84.  
  85.     dcr.5    DOCODE
  86. code_start
  87.     dcr.5    code_end-code_start
  88.  
  89.     jsr    DisableIntr
  90.  
  91.     ;
  92.     ; figure out version
  93.     ;
  94.     jsr    PopASavptr
  95.     move.1    #0, p
  96.     move.5    #24, c.p
  97.     add.a    c, a
  98.     move.a    a, d1
  99.     move.b    (d1), a
  100.     move.2    #$4a, c.p    ; 'J' == last version for S/SX
  101.     bclr    #sGX, st
  102.     ble.b    a, c, got_version
  103.     bset    #sGX, st
  104. got_version
  105.     bclr    #sHIGH, st
  106.  
  107.     ;
  108.     ; get arguments
  109.     ;
  110.     jsr    GETPTR
  111.     jsr    POPHXS
  112.     move.1    #0, p
  113.     move.5    #$ffff0, c.p
  114.     and.a    c, a
  115.     move.a    a, r4
  116.  
  117.     jsr    GETPTR
  118.     jsr    POPHXS
  119.     move.1    #0, p
  120.     move.5    #$ffff0, c.p
  121.     and.a    c, a
  122.     move.a    a, r3
  123.     
  124.     ;
  125.     ; open IO
  126.     ;
  127.     move.5    #$00110, d1
  128.     move.1    #8, a.p
  129.     move.1    a, (d1)
  130.  
  131.     ;
  132.     ; set speed to 9600 baud
  133.     ;
  134.     move.2    #$0d, d1
  135.     move.1    #6, a.p
  136.     move.1    a, (d1)
  137.  
  138.     ;
  139.     ; dump ROM $00000 - $6ffff
  140.     ;
  141. dump_rom_0
  142.     move.a    r3, a
  143.     move.5    #$6fff0, c.p
  144.     bgt.a    a, c, dump_rom_7
  145.     move.a    a, r1
  146.  
  147.     move.a    r4, c
  148.     move.a    c, b
  149.     move.5    #$6fff0, c.p
  150.     ble.a    b, c, end_addr_0
  151.     move.a    c, b
  152. end_addr_0
  153.     subr.a    b, a
  154.     bcc    continue_0
  155.     bra.3    dump_done
  156. continue_0
  157.     move.a    a, r2
  158.  
  159.     bsr.3    prog_start
  160.  
  161.     move.5    #$70000, a.p
  162.     move.a    a, r3
  163.  
  164.     ;
  165.     ; dump ROM $70000 - $7ffff
  166.     ;
  167. dump_rom_7
  168.     move.a    r3, a
  169.     move.5    #$7fff0, c.p
  170.     bgt.a    a, c, dump_done_7
  171.     bra.3    continue_7
  172. dump_done_7
  173.     bbs    #sGX, st, continue_8
  174.     bra.3    dump_done
  175. continue_8
  176.     bra.3    dump_rom_8
  177. continue_7
  178.     move.a    a, r1
  179.  
  180.     move.a    r4, c
  181.     move.a    c, b
  182.     move.5    #$7fff0, c.p
  183.     ble.a    b, c, end_addr_7
  184.     move.a    c, b
  185. end_addr_7
  186.     subr.a    b, a
  187.     bcc    continue_7_2
  188.     bra.3    dump_done
  189. continue_7_2
  190.     move.a    a, r2
  191.  
  192.     bbs    #sGX, st, gx_dump_rom_7
  193.     bsr.3    copy_prog
  194.     move.5    #sx_prog_high, c.p
  195.     jsr    sx_GosubHidC
  196.     bsr.3    copy_prog
  197.     bra.3    dump_done
  198.  
  199. gx_dump_rom_7
  200.     ;
  201.     ; unconfigure devices at 7e000 - 7ffff
  202.     ;
  203.     move.5    #$7f000, c.p
  204.     uncnfg
  205.     move.5    #$7e000, c.p
  206.     uncnfg
  207.  
  208.     bsr.3    prog_start
  209.  
  210.     ;
  211.     ; reconfigure devices at 7e000 - 7ffff
  212.     ;
  213.     move.5    #$ff000, c.p
  214.     config
  215.     move.5    #$7f000, c.p
  216.     config
  217.     move.5    #$ff000, c.p
  218.     config
  219.     move.5    #$7e000, c.p
  220.     config
  221.  
  222.     move.5    #$80000, a.p
  223.     move.a    a, r3
  224.  
  225.     ;
  226.     ; dump ROM $80000 - $bffff
  227.     ;
  228. dump_rom_8
  229.     move.a    r3, a
  230.     move.5    #$bfff0, c.p
  231.     bgt.a    a, c, dump_rom_c
  232.     move.a    a, r1
  233.  
  234.     move.a    r4, c
  235.     move.a    c, b
  236.     move.5    #$bfff0, c.p
  237.     ble.a    b, c, end_addr_8
  238.     move.a    c, b
  239. end_addr_8
  240.     subr.a    b, a
  241.     bcc    continue_8_2
  242.     bra.3    dump_done
  243. continue_8_2
  244.     move.a    a, r2
  245.  
  246.     bsr.3    copy_prog
  247.     move.5    #gx_prog_high, c.p
  248.     jsr    gx_GosubHidC
  249.     bsr.3    copy_prog
  250.  
  251.     move.5    #$c0000, a.p
  252.     move.a    a, r3
  253.  
  254.     ;
  255.     ; dump ROM $c0000 - $fffff
  256.     ;
  257. dump_rom_c
  258.     move.a    r3, a
  259.     move.a    a, r1
  260.  
  261.     move.a    r4, c
  262.     move.a    c, b
  263.     move.5    #$ffff0, c.p
  264.     ble.a    b, c, end_addr_c
  265.     move.a    c, b
  266. end_addr_c
  267.     subr.a    b, a
  268.     bcs    dump_done
  269.     move.a    a, r2
  270.  
  271.     bsr.3    copy_prog
  272.     bset    #sHIGH, st
  273.     jsr    gx_prog_low
  274.     bsr.3    copy_prog
  275.  
  276. dump_done
  277.     ;
  278.     ; close IO
  279.     ;
  280.     bsr.3    send_crnl
  281.     move.5    #$00110, d1
  282.     move.1    #0, a.p
  283.     move.1    a, (d1)
  284.  
  285.     ;
  286.     ; back to RPL
  287.     ;
  288.     jsr    AllowIntr
  289.     jmp    GETPTRLOOP
  290.  
  291. ;
  292. ; exchange program with memory at address prog_low
  293. ;
  294. copy_prog
  295.     move.a    pc, c
  296. prog_offset
  297.     move.5    #prog_start-prog_offset, a.p
  298.     add.a    a, c
  299.     move.a    c, d0
  300.     bbs    #sGX, st, gx_addr
  301.     move.5    #sx_prog_low, d1
  302.     bra.3    sx_addr
  303. gx_addr
  304.     move.5    #gx_prog_low, d1
  305. sx_addr
  306.     move.5    #prog_end-prog_start, a.p
  307.     lsr.a    #4, a
  308.     move.a    a, b
  309.  
  310. copy_word
  311.     move.w    (d0), a
  312.     move.w    (d1), c
  313.     move.w    c, (d0)
  314.     move.w    a, (d1)
  315.     add.a    #16, d0
  316.     add.a    #16, d1
  317.     dec.a    b
  318.     bcc    copy_word
  319.     rtn
  320.  
  321. ;
  322. ; this is the start of the actual dump routine
  323. ;
  324. prog_start
  325.     bbc    #sHIGH, st, skip_uncover_c
  326.     ;
  327.     ; uncover ROM at c0000 - fffff
  328.     ;
  329.     move.5    #$7f000, d0
  330.     move.b    (d0), c
  331.     move.5    #gx_LINECOUNT, d0
  332.     move.b    (d0), c
  333.     bset    #7, c
  334.     move.b    c, (d0)
  335.     move.5    #$00128, d0
  336.     move.b    c, (d0)
  337.     move.5    #$c0000, c.p
  338.     uncnfg
  339.     uncnfg
  340.  
  341. skip_uncover_c
  342.     ;
  343.     ; get start address and number of words
  344.     ;
  345.     move.a    r1, a
  346.     move.a    a, d0
  347.     move.a    r2, a
  348.  
  349.     ;
  350.     ; dump the ROM
  351.     ;
  352. loop
  353.     move.a    a, r0
  354.     bsr.3    send_addr
  355.     move.2    #$3a, c.p
  356.     bsr.3    send_char
  357.         move.w    (d0), c
  358.     bsr.3    send_data
  359.     bsr.3    send_crnl
  360.  
  361.     add.a    #16, d0
  362.     move.a    r0, a
  363.     sub.a    #16, a
  364.     bcc    loop
  365.  
  366.     bbc    #sHIGH, st, skip_cover_c
  367.     ;
  368.     ; reconfigure memory ports at c0000
  369.     ;
  370.     move.5    #$c0000, c.p
  371.     config
  372.     config
  373.     config
  374.     config
  375.     move.5    #gx_LINECOUNT, d0
  376.     move.b    (d0), c
  377.     bclr    #7, c
  378.     move.b    c, (d0)
  379.     move.5    #$00128, d0
  380.     move.b    c, (d0)
  381.     move.5    #$7f040, d0
  382.     move.b    (d0), c
  383.  
  384. skip_cover_c
  385.     rtn
  386.  
  387. ;
  388. ; send data in C.W as hex characters
  389. ;
  390. send_data
  391.     move.w    c, b
  392.     move.2    #$0f, c.p
  393.     move.b    c, d
  394.     bra.3    send_all
  395.     
  396. ;
  397. ; send addr in D0 as hex characters
  398. ;
  399. send_addr
  400.     exg.a    a, d0
  401.     move.a    a, c
  402.     exg.a    a, d0
  403.     exg.1    p, c.4
  404.     exg.1    p, c.0
  405.     exg.1    p, c.4
  406.     exg.1    p, c.3
  407.     exg.1    p, c.1
  408.     exg.1    p, c.3
  409.     move.a    c, b
  410.     move.2    #$04, c.p
  411.     move.b    c, d
  412.  
  413. ;
  414. ; send D.B many nibbles from B.W
  415. ;
  416. send_all
  417.     clr.b    c
  418.     move.p    b, c
  419.     bsr.3    send_hex_nib
  420.     lsr.w    #4, b
  421.     dec.b    d
  422.     bcc    send_all
  423.     rtn
  424.  
  425. ;
  426. ; send "\n\r"
  427. ;
  428. send_crnl
  429.     move.2    #$0d, c.p
  430.     bsr.3    send_char
  431.     move.2    #$0a, c.p
  432.     bsr.3    send_char
  433.     rtn
  434.  
  435. ;
  436. ; send nibble in C.B as hex character
  437. ;
  438. send_hex_nib
  439.     move.2    #$30, a.p
  440.     add.b    a, c
  441.     move.2    #$39, a.p
  442.     ble.b    c, a, send_char
  443.     move.2    #$07, a.p
  444.     add.b    a, c
  445. ;
  446. ; send character in C.B
  447. ;
  448. send_char
  449.     move.5    #$00112, d1
  450. xmtrdy
  451.     move.1    (d1), a
  452.     bbs    #0, a, xmtrdy
  453.     move.2    #$16, d1
  454.     move.b    c, (d1)
  455.     rtn
  456.  
  457. prog_end
  458.     dcr.8    $00000000
  459.     dcr.8    $00000000
  460.  
  461. code_end
  462.  
  463.     dcr.5    SEMI    ; end of DISPATCH
  464.     dcr.5    SEMI    ; end of program object
  465.